﻿using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Drawing;
using System.IO;
using System.Text;
using netDxf;
using netDxf.Blocks;
using netDxf.Collections;
using netDxf.Entities;
using netDxf.Header;
using netDxf.Objects;
using netDxf.Tables;
using netDxf.Units;
using Attribute = netDxf.Entities.Attribute;
using Image = netDxf.Entities.Image;
using Point = netDxf.Entities.Point;
using Trace = netDxf.Entities.Trace;

namespace TestDxfDocument
{
    class Collets
    {
        /*
        public static void DoubleAngleCollets(Dictionary<string, Object> data)  //双角夹头
        {
            DxfDocument dxf = new DxfDocument();
            Layer contour = new Layer("contour") { Color = AciColor.Cyan };    //轮廓层
            Layer dimensioning = new Layer("dimensioning");    //尺寸层
            Layer refin = new Layer("refin") { Color = AciColor.Red };    //基准线/内轮廓
            Layer centre = new Layer("centre") { Color = AciColor.Yellow };    //中心线
            Layer textlayer = new Layer("textlayer") { Color = AciColor.Blue };    //文本层
            Layer hatching = new Layer("hatching") { Color = AciColor.Blue };    //填充层
            Layer additionalline = new Layer("additionalline") { Color = AciColor.Cyan };    //附加线
            Layer cutting = new Layer("cutting") { Color = AciColor.Red };    //切削层
            Layer nocutting = new Layer("nocutting");    //非切削层
            Layer skcontour = new Layer("skcontour") { Color = AciColor.Cyan };    //sk轮廓层
            Layer skdimensioning = new Layer("skdimensioning");    //sk尺寸线层
            Layer skrefin = new Layer("skrefin") { Color = AciColor.Red };    //sk基准线/内轮廓
            Layer sktext = new Layer("sktext") { Color = AciColor.Blue };  //sk文本
            Layer skhatching = new Layer("skhatching") { Color = AciColor.Blue };    //sk填充
            Layer skadditionlline = new Layer("skadditionlline") { Color = AciColor.Cyan };    //sk附加线
            Layer skviewcontour = new Layer("skviewcontour") { Color = AciColor.Cyan };    //skview轮廓
            Layer skviewdimensioning = new Layer("skviewdimensioning");    //skview尺寸线层

            double pi = Math.PI;

            double oal = 44;
            double lcob = 26;
            double lct = 25;
            double lsc = 16;
            double lc = 3;
            double dgui = 16;
            double dn = 15;
            double dcob = 10;
            double lgui = 7;
            double lf1 = 1;//缝隙宽度
            double dconws = 8;
            double dclc = 15;
            double bd = 24;
            double x1 = 0.5;
            double x2 = 1;
            double ta1 = pi / 6;
            double ta2 = pi * 2 / 3;
            string path = "E:\\dxfp\\DoubleAngleCollets.dxf";
            
            double oal = Convert.ToDouble(data["oal"]);
            double lcob = Convert.ToDouble(data["lcob"]);
            double lct = Convert.ToDouble(data["lct"]);
            double lsc = Convert.ToDouble(data["lsc"]);
            double lc = Convert.ToDouble(data["lc"]);
            double dcui = Convert.ToDouble(data["dcui"]);
            double dn = Convert.ToDouble(data["dn"]);
            double dcob = Convert.ToDouble(data["dcob"]);
            double lcui = Convert.ToDouble(data["lcui"]);
            double lf = Convert.ToDouble(data["lf"]);//缝隙宽度
            double dconws = Convert.ToDouble(data["dconws"]);
            double dclc = Convert.ToDouble(data["dclc"]);
            double bd = Convert.ToDouble(data["bd"]);
            double x1 = Convert.ToDouble(data["x1"]);
            double x2 = Convert.ToDouble(data["x2"]);
            double ta1 = Convert.ToDouble(data["ta1"])*pi/180;
            double ta2 = Convert.ToDouble(data["ta2"])*pi/180;
            string path = Convert.ToDouble(data["path"]);
            
            Vector2 p0 = new Vector2(0, 0);
            Vector2 p0p = new Vector2(p0.X + oal, p0.Y);
            Vector2 p1 = new Vector2(p0.X, p0.Y - dcob / 2);
            Vector2 p2 = new Vector2(p0.X, p0.Y - dgui / 2);
            Vector2 p3 = new Vector2(p0.X + lgui, p2.Y);
            Vector2 p4 = new Vector2(p3.X + x1, p0.Y - dn / 2);
            Vector2 p5 = new Vector2(p0.X + lct, p4.Y);
            Vector2 p6 = new Vector2(p5.X + x2, p5.Y - x2);
            Vector2 p7 = new Vector2(p6.X + ((bd - dn) / 2 - x2) / Math.Tan(ta1 / 2), p0.Y - bd / 2);
            Vector2 p8 = new Vector2(p0p.X - lc, p0.Y - dclc / 2);
            Vector2 p9 = new Vector2(p0p.X, p8.Y);
            Vector2 p10 = new Vector2(p9.X, p0.Y - dconws / 2);
            Vector2 p11 = new Vector2(p10.X - lsc, p10.Y);
            Vector2 p12 = new Vector2(p0.X + lcob, p0.Y - dcob / 2);
            Vector2 p13 = new Vector2(p0.X, -p2.Y);
            Vector2 p14 = new Vector2(p3.X, -p3.Y);
            Vector2 p15 = new Vector2(p4.X, -p4.Y);
            Vector2 p16 = new Vector2(p5.X - x1, -p5.Y);
            Vector2 p17 = new Vector2(p5.X, -p5.Y);
            Vector2 p18 = new Vector2(p6.X, -p6.Y);
            Vector2 p19 = new Vector2(p7.X, -p7.Y);
            Vector2 p20 = new Vector2(p8.X, -p8.Y);
            Vector2 p21 = new Vector2(p9.X, -p9.Y);
            Vector2 p22 = new Vector2(p9.X, p0.Y + lf1 / 2);
            Vector2 p23 = new Vector2(p15.X + x2, p22.Y);
            Vector2 p24 = new Vector2(p23.X - x1, p0.Y);



            LwPolyline poly1 = new LwPolyline(); //轮廓
            poly1.Vertexes.Add(new LwPolylineVertex(p0));
            poly1.Vertexes.Add(new LwPolylineVertex(p1));
            poly1.Vertexes.Add(new LwPolylineVertex(p2));
            poly1.Vertexes.Add(new LwPolylineVertex(p3));
            poly1.Vertexes.Add(new LwPolylineVertex(p4));
            poly1.Vertexes.Add(new LwPolylineVertex(p5));
            poly1.Vertexes.Add(new LwPolylineVertex(p6));
            poly1.Vertexes.Add(new LwPolylineVertex(p7));
            poly1.Vertexes.Add(new LwPolylineVertex(p8));
            poly1.Vertexes.Add(new LwPolylineVertex(p9));
            poly1.Vertexes.Add(new LwPolylineVertex(p10));
            poly1.Vertexes.Add(new LwPolylineVertex(p11));
            poly1.Vertexes.Add(new LwPolylineVertex(p12));
            poly1.Vertexes.Add(new LwPolylineVertex(p1));
            fun.PolyFill(dxf, poly1, 0.3, contour);

            LwPolyline poly2 = new LwPolyline();
            poly2.Vertexes.Add(new LwPolylineVertex(p0));
            poly2.Vertexes.Add(new LwPolylineVertex(p13));
            poly2.Vertexes.Add(new LwPolylineVertex(p14));
            poly2.Vertexes.Add(new LwPolylineVertex(p15));
            poly2.Vertexes.Add(new LwPolylineVertex(p16));
            poly2.Vertexes.Add(new LwPolylineVertex(p17));
            poly2.Vertexes.Add(new LwPolylineVertex(p18));
            poly2.Vertexes.Add(new LwPolylineVertex(p19));
            poly2.Vertexes.Add(new LwPolylineVertex(p20));
            poly2.Vertexes.Add(new LwPolylineVertex(p21));
            poly2.Vertexes.Add(new LwPolylineVertex(p22));
            poly2.Vertexes.Add(new LwPolylineVertex(p23));
            poly2.Vertexes.Add(new LwPolylineVertex(p24));
            fun.PolyFill(dxf, poly2, 0.3, contour);

            Vector2[] line1 = { p22, p10 };
            fun.drawBLine(dxf, line1, 0.3, contour);
            Vector2[] line2 = { p14, new Vector2(p14.X, p0.Y) };
            fun.drawBLine(dxf, line2, 0.3, contour);
            Vector2[] line3 = { p15, new Vector2(p15.X, p0.Y) };
            fun.drawBLine(dxf, line3, 0.3, contour);
            Vector2[] line4 = { p17, new Vector2(p17.X, p22.Y) };
            fun.drawBLine(dxf, line4, 0.3, contour);
            Vector2[] line5 = { p18, new Vector2(p18.X, p22.Y) };
            fun.drawBLine(dxf, line5, 0.3, contour);
            Vector2[] line6 = { p19, new Vector2(p19.X, p22.Y) };
            fun.drawBLine(dxf, line6, 0.3, contour);
            Vector2[] line7 = { p20, new Vector2(p20.X, p22.Y) };
            fun.drawBLine(dxf, line7, 0.3, contour);

            Vector2[] cenline1 = { new Vector2(p0.X - 2, p0.Y), new Vector2(p0p.X + 2, p0.Y) };//主轴中心线
            fun.drawPlinetype(dxf, cenline1, centre, Linetype.Center);

            LwPolyline hatchpoly1 = new LwPolyline(); //填充
            hatchpoly1.Vertexes.Add(new LwPolylineVertex(p1));
            hatchpoly1.Vertexes.Add(new LwPolylineVertex(p2));
            hatchpoly1.Vertexes.Add(new LwPolylineVertex(p3));
            hatchpoly1.Vertexes.Add(new LwPolylineVertex(p4));
            hatchpoly1.Vertexes.Add(new LwPolylineVertex(p5));
            hatchpoly1.Vertexes.Add(new LwPolylineVertex(p6));
            hatchpoly1.Vertexes.Add(new LwPolylineVertex(p7));
            hatchpoly1.Vertexes.Add(new LwPolylineVertex(p8));
            hatchpoly1.Vertexes.Add(new LwPolylineVertex(p9));
            hatchpoly1.Vertexes.Add(new LwPolylineVertex(p10));
            hatchpoly1.Vertexes.Add(new LwPolylineVertex(p11));
            hatchpoly1.Vertexes.Add(new LwPolylineVertex(p12));
            hatchpoly1.IsClosed = true;
            String[] htype1 = new String[100];
            Line[] hline1 = new Line[100];
            int hnumst1 = hatchpoly1.Explode().Count;  //记录爆炸后，线段有多少
            for (int i = 0; i < hnumst1; i++)
            {
                htype1[i] = hatchpoly1.Explode()[i].Type.ToString();    //将所有的元素记录成一个数组
                if (htype1[i] == "Line")
                {
                    hline1[i] = (Line)hatchpoly1.Explode()[i];
                }
            }
            fun.hatchsubofline(dxf, htype1, hnumst1, 45, 5, hline1, hatching);

            DimensionStyle dimensionStyle = fun.CreateDimStyle();//标注
            dimensionStyle.ArrowSize = 0.2;
            dimensionStyle.DimArrow1 = DimensionArrowhead.Closedfilled;
            dimensionStyle.DimArrow2 = DimensionArrowhead.Closedfilled;
            dimensionStyle.TextHeight = 0.5;
            double offset = 7;

            LinearDimension linedim1 = new LinearDimension(new Line(p2, p9), offset * 3, 180, dimensionStyle);
            fun.dxflinedim(dxf, linedim1, oal);
            LinearDimension linedim2 = new LinearDimension(new Line(p7, p19), offset * 3, 270, dimensionStyle);
            fun.dxflinedim(dxf, linedim2, bd);
            LinearDimension linedim3 = new LinearDimension(new Line(p9, p21), offset * 1.5, 270, dimensionStyle);
            fun.dxflinedim(dxf, linedim3, dclc);
            LinearDimension linedim4 = new LinearDimension(new Line(p13, p2), offset * 1.5, 90, dimensionStyle);
            fun.dxflinedim(dxf, linedim4, dgui);
            LinearDimension linedim5 = new LinearDimension(new Line(p2, p12), offset * 2, 180, dimensionStyle);
            fun.dxflinedim(dxf, linedim5, lcob);
            LinearDimension linedim6 = new LinearDimension(new Line(p11, p10), offset * 2, 180, dimensionStyle);
            fun.dxflinedim(dxf, linedim6, lsc);


            dxf.DrawingVariables.AcadVer = DxfVersion.AutoCad2007;
            dxf.Save(path);
        }

        public static void PropertiesOfFerrules(Dictionary<string, Object> data)  //
        {
            DxfDocument dxf = new DxfDocument();
            Layer contour = new Layer("contour") { Color = AciColor.Cyan };    //轮廓层
            Layer dimensioning = new Layer("dimensioning");    //尺寸层
            Layer refin = new Layer("refin") { Color = AciColor.Red };    //基准线/内轮廓
            Layer centre = new Layer("centre") { Color = AciColor.Yellow };    //中心线
            Layer textlayer = new Layer("textlayer") { Color = AciColor.Blue };    //文本层
            Layer hatching = new Layer("hatching") { Color = AciColor.Blue };    //填充层
            Layer additionalline = new Layer("additionalline") { Color = AciColor.Cyan };    //附加线
            Layer cutting = new Layer("cutting") { Color = AciColor.Red };    //切削层
            Layer nocutting = new Layer("nocutting");    //非切削层
            Layer skcontour = new Layer("skcontour") { Color = AciColor.Cyan };    //sk轮廓层
            Layer skdimensioning = new Layer("skdimensioning");    //sk尺寸线层
            Layer skrefin = new Layer("skrefin") { Color = AciColor.Red };    //sk基准线/内轮廓
            Layer sktext = new Layer("sktext") { Color = AciColor.Blue };  //sk文本
            Layer skhatching = new Layer("skhatching") { Color = AciColor.Blue };    //sk填充
            Layer skadditionlline = new Layer("skadditionlline") { Color = AciColor.Cyan };    //sk附加线
            Layer skviewcontour = new Layer("skviewcontour") { Color = AciColor.Cyan };    //skview轮廓
            Layer skviewdimensioning = new Layer("skviewdimensioning");    //skview尺寸线层

            double pi = Math.PI;

            double oal = 110;
            double tl = 60;
            double lsc = 30;
            double bd = 24;
            double dcon = 10;
            double dc = 20;
            double lcon = 80;
            double x1 = 1;
            double x2 = 2;
            double df = 2;
            double r1 = 2;
            double r2 = 4;
            double lf = 40;
            double lf1 = 25;
            double dconws = 12;
            double ta = 2 * pi / 180;
            string path = "E:\\dxfp\\PropertiesOfFerrules.dxf";
            
            double oal = Convert.ToDouble(data["oal"]);
            double tl = Convert.ToDouble(data["tl"]);
            double lsc = Convert.ToDouble(data["lsc"]);
            double bd = Convert.ToDouble(data["bd"]);
            double dcon = Convert.ToDouble(data["dcon"]);
            double dc = Convert.ToDouble(data["dc"]);
            double lcon = Convert.ToDouble(data["lcon"]);
            double x1 = Convert.ToDouble(data["x1"]);
            double x2 = Convert.ToDouble(data["x2"]);
            double df = Convert.ToDouble(data["df"]);
            double r1 = Convert.ToDouble(data["r1"]);
            double r2 = Convert.ToDouble(data["r2"]);
            double lf = Convert.ToDouble(data["lf"]);
            double lf1 = Convert.ToDouble(data["lf1"]);
            double dconws = Convert.ToDouble(data["dconws"]);
            double ta = Convert.ToDouble(data["ta"]);
            string path = Convert.ToDouble(data["path"]);
            
            Vector2 p0 = new Vector2(0, 0);
            Vector2 p0p = new Vector2(p0.X + oal, p0.Y);
            Vector2 p1 = new Vector2(p0.X, p0.Y - (dcon / 2 - x1));
            Vector2 p2 = new Vector2(p1.X + x1, p1.Y - x1);
            Vector2 p3 = new Vector2(p0.X + (oal - lcon - (bd - dcon) / 2), p2.Y);
            Vector2 p4 = new Vector2(p0.X + (oal - lcon), p0.Y - dc / 2);
            Vector2 p5 = new Vector2(p0.X + (oal - tl - x1), p4.Y);
            Vector2 p6 = new Vector2(p0.X + (oal - tl), p0.Y - (bd / 2 - (tl - x1) * Math.Tan(ta / 2)));
            Vector2 p7 = new Vector2(p0.Y + oal - x1, p0.Y - bd / 2);
            Vector2 p8 = new Vector2(p0p.X, p7.Y + x1);

            Vector2 p9 = new Vector2(p0p.X, p0.Y - df / 2);
            Vector2 p10 = new Vector2(p9.X - lf1, p9.Y);
            Vector2 p11 = new Vector2(p10.X - r2, p10.Y - r2);
            Vector2 p12 = new Vector2(p0p.X - lf, p11.Y);
            Vector2 p13 = new Vector2(p12.X, p9.Y);
            Vector2 p14 = new Vector2(p4.X + (lcon - tl) / 2 + r1, p13.Y);
            Vector2 p15 = new Vector2(p14.X - 2 * r1, p14.Y);
            Vector2 pm1 = new Vector2(p1.X, -p1.Y);
            Vector2 pm2 = new Vector2(p2.X, -p2.Y);
            Vector2 pm3 = new Vector2(p3.X, -p3.Y);
            Vector2 pm4 = new Vector2(p4.X, -p4.Y);
            Vector2 pm5 = new Vector2(p5.X, -p5.Y);
            Vector2 pm6 = new Vector2(p6.X, -p6.Y);
            Vector2 pm7 = new Vector2(p7.X, -p7.Y);
            Vector2 pm8 = new Vector2(p8.X, -p8.Y);
            Vector2 pm9 = new Vector2(p9.X, -p9.Y);
            Vector2 pm10 = new Vector2(p10.X, -p10.Y);
            Vector2 pm11 = new Vector2(p11.X, -p11.Y);
            Vector2 pm12 = new Vector2(p12.X, -p12.Y);
            Vector2 pm13 = new Vector2(p13.X, -p13.Y);
            Vector2 pm14 = new Vector2(p14.X, -p14.Y);
            Vector2 pm15 = new Vector2(p15.X, -p15.Y);

            LwPolyline poly1 = new LwPolyline(); //外轮廓
            poly1.Vertexes.Add(new LwPolylineVertex(p0));
            poly1.Vertexes.Add(new LwPolylineVertex(pm1));
            poly1.Vertexes.Add(new LwPolylineVertex(pm2));
            poly1.Vertexes.Add(new LwPolylineVertex(pm3));
            poly1.Vertexes.Add(new LwPolylineVertex(pm4));
            poly1.Vertexes.Add(new LwPolylineVertex(pm5));
            poly1.Vertexes.Add(new LwPolylineVertex(pm6));
            poly1.Vertexes.Add(new LwPolylineVertex(pm7));
            poly1.Vertexes.Add(new LwPolylineVertex(pm8));
            poly1.Vertexes.Add(new LwPolylineVertex(pm9));
            poly1.Vertexes.Add(new LwPolylineVertex(pm10));
            poly1.Vertexes[10].Bulge = Math.Tan(pi / 8);
            poly1.Vertexes.Add(new LwPolylineVertex(pm11));
            poly1.Vertexes.Add(new LwPolylineVertex(pm12));
            poly1.Vertexes.Add(new LwPolylineVertex(pm13));
            poly1.Vertexes.Add(new LwPolylineVertex(pm14));
            poly1.Vertexes[14].Bulge = Math.Tan(pi / 4);
            poly1.Vertexes.Add(new LwPolylineVertex(pm15));
            poly1.Vertexes.Add(new LwPolylineVertex(p15));
            poly1.Vertexes[16].Bulge = Math.Tan(pi / 4);
            poly1.Vertexes.Add(new LwPolylineVertex(p14));
            poly1.Vertexes.Add(new LwPolylineVertex(p13));
            poly1.Vertexes.Add(new LwPolylineVertex(p12));
            poly1.Vertexes.Add(new LwPolylineVertex(p11));
            poly1.Vertexes[20].Bulge = Math.Tan(pi / 8);
            poly1.Vertexes.Add(new LwPolylineVertex(p10));
            poly1.Vertexes.Add(new LwPolylineVertex(p9));
            poly1.Vertexes.Add(new LwPolylineVertex(p8));
            poly1.Vertexes.Add(new LwPolylineVertex(p7));
            poly1.Vertexes.Add(new LwPolylineVertex(p6));
            poly1.Vertexes.Add(new LwPolylineVertex(p5));
            poly1.Vertexes.Add(new LwPolylineVertex(p4));
            poly1.Vertexes.Add(new LwPolylineVertex(p3));
            poly1.Vertexes.Add(new LwPolylineVertex(p2));
            poly1.Vertexes.Add(new LwPolylineVertex(p1));
            poly1.Vertexes.Add(new LwPolylineVertex(p0));
            fun.PolyFill(dxf, poly1, 0.3, contour);

            Vector2[] line1 = { pm2, new Vector2(pm2.X, p0.Y) };
            fun.drawBLine(dxf, line1, 0.3, contour);
            Vector2[] line2 = { pm3, new Vector2(pm3.X, p0.Y) };
            fun.drawBLine(dxf, line2, 0.3, contour);
            Vector2[] line3 = { pm4, new Vector2(pm4.X, p0.Y) };
            fun.drawBLine(dxf, line3, 0.3, contour);
            Vector2[] line4 = { pm5, new Vector2(pm5.X, p0.Y + df / 2) };
            fun.drawBLine(dxf, line4, 0.3, contour);
            Vector2[] line5 = { pm6, new Vector2(pm6.X, p0.Y + df / 2) };
            fun.drawBLine(dxf, line5, 0.3, contour);
            Vector2[] line6 = { pm7, new Vector2(pm7.X, p0.Y + df / 2) };
            fun.drawBLine(dxf, line6, 0.3, contour);

            Vector2 p16 = new Vector2(p0p.X - lsc, p11.Y);
            Vector2 p17 = new Vector2(p0p.X - lsc, p0.Y - dconws / 2);
            Vector2 p18 = new Vector2(p0p.X, p17.Y);

            LwPolyline poly2 = new LwPolyline(); //
            poly2.Vertexes.Add(new LwPolylineVertex(p16));
            poly2.Vertexes.Add(new LwPolylineVertex(p17));
            poly2.Vertexes.Add(new LwPolylineVertex(p18));
            fun.PolyFill(dxf, poly2, 0.3, contour);

            Vector2[] cenline1 = { new Vector2(p0.X - 2, p0.Y), new Vector2(p0p.X + 2, p0.Y) };//主轴中心线
            fun.drawPlinetype(dxf, cenline1, centre, Linetype.Center);


            LwPolyline hatchpoly1 = new LwPolyline(); //填充（填充部分带圆弧）
            hatchpoly1.Vertexes.Add(new LwPolylineVertex(p0));
            hatchpoly1.Vertexes.Add(new LwPolylineVertex(new Vector2(p15.X, p0.Y)));
            hatchpoly1.Vertexes.Add(new LwPolylineVertex(p15));
            hatchpoly1.Vertexes[2].Bulge = Math.Tan(pi / 4);//arc
            hatchpoly1.Vertexes.Add(new LwPolylineVertex(p14));
            hatchpoly1.Vertexes.Add(new LwPolylineVertex(p13));
            hatchpoly1.Vertexes.Add(new LwPolylineVertex(p12));
            hatchpoly1.Vertexes.Add(new LwPolylineVertex(p16));
            hatchpoly1.Vertexes.Add(new LwPolylineVertex(p17));
            hatchpoly1.Vertexes.Add(new LwPolylineVertex(p18));
            hatchpoly1.Vertexes.Add(new LwPolylineVertex(p8));
            hatchpoly1.Vertexes.Add(new LwPolylineVertex(p7));
            hatchpoly1.Vertexes.Add(new LwPolylineVertex(p6));
            hatchpoly1.Vertexes.Add(new LwPolylineVertex(p5));
            hatchpoly1.Vertexes.Add(new LwPolylineVertex(p4));
            hatchpoly1.Vertexes.Add(new LwPolylineVertex(p3));
            hatchpoly1.Vertexes.Add(new LwPolylineVertex(p2));
            hatchpoly1.Vertexes.Add(new LwPolylineVertex(p1));
            hatchpoly1.IsClosed = true;

            //fun.PolyFill(dxf, hatchpoly1, 0.1, hatching);
            List<HatchBoundaryPath> boundary = new List<HatchBoundaryPath>//建立需要填充部分的边界，但不打印
            {
                new HatchBoundaryPath(new List<EntityObject> {hatchpoly1}),           //详见hatchtest2
                //new HatchBoundaryPath(new List<EntityObject> {poly2, ellipse1})    //可添加多个轮廓，如有内外轮廓，填充中间部分
            };

            Hatch hatch = new Hatch(HatchPattern.Line, boundary, false);
            hatch.Pattern.Angle = 45;
            hatch.Pattern.Scale = 5;
            String[] type = new String[100];
            Line[] line = new Line[100];
            Arc[] arc = new Arc[100];
            int numst1 = hatchpoly1.Explode().Count;
            int numst = numst1;
            for (int i = 0; i < numst; i++)
            {
                type[i] = hatchpoly1.Explode()[i].Type.ToString();
                if (type[i] == "Line")
                {
                    line[i] = (Line)hatchpoly1.Explode()[i];
                }
                if (type[i] == "Arc")
                {
                    arc[i] = (Arc)hatchpoly1.Explode()[i];
                }
            }

            fun.hatchsuboflineandarc(dxf, type, numst, hatch.Pattern.Angle, hatch.Pattern.Scale, line, arc, hatching);

            //dxf.AddEntity(hatchpoly1);//(不打印填充轮廓)

            DimensionStyle dimensionStyle = fun.CreateDimStyle();//标注
            dimensionStyle.ArrowSize = 0.2;
            dimensionStyle.DimArrow1 = DimensionArrowhead.Closedfilled;
            dimensionStyle.DimArrow2 = DimensionArrowhead.Closedfilled;
            dimensionStyle.TextHeight = 0.5;
            double offset = 7;

            LinearDimension linedim1 = new LinearDimension(new Line(p1, p8), offset * 3, 180, dimensionStyle);
            fun.dxflinedim(dxf, linedim1, oal);
            LinearDimension linedim2 = new LinearDimension(new Line(p7, pm7), offset * 1, 270, dimensionStyle);
            fun.dxflinedim(dxf, linedim2, bd);
            LinearDimension linedim3 = new LinearDimension(new Line(p6, p8), offset, 180, dimensionStyle);
            fun.dxflinedim(dxf, linedim3, tl);
            LinearDimension linedim4 = new LinearDimension(new Line(p4, p8), offset * 2, 180, dimensionStyle);
            fun.dxflinedim(dxf, linedim4, lcon);
            LinearDimension linedim5 = new LinearDimension(new Line(p2, pm2), offset, 90, dimensionStyle);
            fun.dxflinedim(dxf, linedim5, dcon);
            LinearDimension linedim6 = new LinearDimension(new Line(p4, pm4), offset * 6, 90, dimensionStyle);
            fun.dxflinedim(dxf, linedim6, dc);

            dxf.DrawingVariables.AcadVer = DxfVersion.AutoCad2007;
            dxf.Save(path);
        }

        public static void ConicalClampingSleevesWithRetainingThread(Dictionary<string, Object> data)  //带固定螺纹的锥形夹套
        {
            DxfDocument dxf = new DxfDocument();
            Layer contour = new Layer("contour") { Color = AciColor.Cyan };    //轮廓层
            Layer dimensioning = new Layer("dimensioning");    //尺寸层
            Layer refin = new Layer("refin") { Color = AciColor.Red };    //基准线/内轮廓
            Layer centre = new Layer("centre") { Color = AciColor.Yellow };    //中心线
            Layer textlayer = new Layer("textlayer") { Color = AciColor.Blue };    //文本层
            Layer hatching = new Layer("hatching") { Color = AciColor.Blue };    //填充层
            Layer additionalline = new Layer("additionalline") { Color = AciColor.Cyan };    //附加线
            Layer cutting = new Layer("cutting") { Color = AciColor.Red };    //切削层
            Layer nocutting = new Layer("nocutting");    //非切削层
            Layer skcontour = new Layer("skcontour") { Color = AciColor.Cyan };    //sk轮廓层
            Layer skdimensioning = new Layer("skdimensioning");    //sk尺寸线层
            Layer skrefin = new Layer("skrefin") { Color = AciColor.Red };    //sk基准线/内轮廓
            Layer sktext = new Layer("sktext") { Color = AciColor.Blue };  //sk文本
            Layer skhatching = new Layer("skhatching") { Color = AciColor.Blue };    //sk填充
            Layer skadditionlline = new Layer("skadditionlline") { Color = AciColor.Cyan };    //sk附加线
            Layer skviewcontour = new Layer("skviewcontour") { Color = AciColor.Cyan };    //skview轮廓
            Layer skviewdimensioning = new Layer("skviewdimensioning");    //skview尺寸线层

            double pi = Math.PI;

            double oal = 135;
            double lcob = 95;
            double lsc = 39;
            double lcol = 128;
            double thlgth = 35;
            double lgui = 25;
            double x1 = 1;
            double x2 = 4;
            double tl = lcol - thlgth - x1 - lgui - x2;
            double lc = 90;
            double df = 2;
            double r1 = 4;
            double thod = 28;
            double dgui = 30;
            double dcob = 16;
            double bd = 60;
            double dclc = 18;
            double dconws = 14;
            double ta = 10 * pi / 180;
            string path = "E:\\dxfp\\ConicalClampingSleevesWithRetainingThread.dxf";

            Vector2 p0 = new Vector2(0, 0);
            Vector2 p0p = new Vector2(p0.X + oal, p0.Y);
            Vector2 p1 = new Vector2(p0.X, p0.Y - dcob / 2);
            Vector2 p2 = new Vector2(p0.X, p0.Y - thod / 2 + x1);
            Vector2 p3 = new Vector2(p0.X + x1, p0.Y - thod / 2);
            Vector2 p4 = new Vector2(p0.X + thlgth, p3.Y);
            Vector2 p5 = new Vector2(p4.X + x1, p0.Y - dgui / 2);
            Vector2 p6 = new Vector2(p5.X + lgui, p5.Y);
            Vector2 p7 = new Vector2(p6.X + x2, p0.Y - (bd / 2 - tl * Math.Tan(ta / 2)));
            Vector2 p8 = new Vector2(p0.X + lcol, p0.Y - bd / 2);
            Vector2 p9 = new Vector2(p0p.X, p0.Y - dclc / 2);
            Vector2 p10 = new Vector2(p0p.X, p0.Y - df / 2);
            Vector2 p11 = new Vector2(p0p.X - lc + r1, p10.Y);
            Vector2 p12 = new Vector2(p11.X - 2 * r1, p11.Y);
            Vector2 pm12 = new Vector2(p12.X, -p12.Y);
            Vector2 pm11 = new Vector2(p11.X, -p11.Y);
            Vector2 pm10 = new Vector2(p10.X, -p10.Y);
            Vector2 pm9 = new Vector2(p9.X, -p9.Y);
            Vector2 pm8 = new Vector2(p8.X, -p8.Y);
            Vector2 pm7 = new Vector2(p7.X, -p7.Y);
            Vector2 pm6 = new Vector2(p6.X, -p6.Y);
            Vector2 pm5 = new Vector2(p5.X, -p5.Y);
            Vector2 pm4 = new Vector2(p4.X, -p4.Y);
            Vector2 pm3 = new Vector2(p3.X, -p3.Y);
            Vector2 pm2 = new Vector2(p2.X, -p2.Y);
            Vector2 p13 = new Vector2(p0.X + lcob, p0.Y - dcob / 2);
            Vector2 p14 = new Vector2(p0p.X - lsc, p0.Y - dconws / 2);
            Vector2 p15 = new Vector2(p0p.X, p0.Y - dconws / 2);


            LwPolyline poly1 = new LwPolyline(); //外轮廓
            poly1.Vertexes.Add(new LwPolylineVertex(p0));
            poly1.Vertexes.Add(new LwPolylineVertex(pm2));
            poly1.Vertexes.Add(new LwPolylineVertex(pm3));
            poly1.Vertexes.Add(new LwPolylineVertex(pm4));
            poly1.Vertexes.Add(new LwPolylineVertex(pm5));
            poly1.Vertexes.Add(new LwPolylineVertex(pm6));
            poly1.Vertexes.Add(new LwPolylineVertex(pm7));
            poly1.Vertexes.Add(new LwPolylineVertex(pm8));
            poly1.Vertexes.Add(new LwPolylineVertex(pm9));
            poly1.Vertexes.Add(new LwPolylineVertex(pm10));
            poly1.Vertexes.Add(new LwPolylineVertex(pm11));
            poly1.Vertexes[10].Bulge = Math.Tan(pi / 4);
            poly1.Vertexes.Add(new LwPolylineVertex(pm12));
            poly1.Vertexes.Add(new LwPolylineVertex(p12));
            poly1.Vertexes[12].Bulge = Math.Tan(pi / 4);
            poly1.Vertexes.Add(new LwPolylineVertex(p11));
            poly1.Vertexes.Add(new LwPolylineVertex(p10));
            poly1.Vertexes.Add(new LwPolylineVertex(p9));
            poly1.Vertexes.Add(new LwPolylineVertex(p8));
            poly1.Vertexes.Add(new LwPolylineVertex(p7));
            poly1.Vertexes.Add(new LwPolylineVertex(p6));
            poly1.Vertexes.Add(new LwPolylineVertex(p5));
            poly1.Vertexes.Add(new LwPolylineVertex(p4));
            poly1.Vertexes.Add(new LwPolylineVertex(p3));
            poly1.Vertexes.Add(new LwPolylineVertex(p2));
            poly1.Vertexes.Add(new LwPolylineVertex(p1));
            poly1.Vertexes.Add(new LwPolylineVertex(p0));
            fun.PolyFill(dxf, poly1, 0.3, contour);

            LwPolyline poly2 = new LwPolyline(); //外轮廓
            poly2.Vertexes.Add(new LwPolylineVertex(p1));
            poly2.Vertexes.Add(new LwPolylineVertex(p13));
            poly2.Vertexes.Add(new LwPolylineVertex(p14));
            poly2.Vertexes.Add(new LwPolylineVertex(p15));
            fun.PolyFill(dxf, poly2, 0.3, contour);

            Vector2[] line1 = { pm3, new Vector2(pm3.X, p0.Y) };
            fun.drawBLine(dxf, line1, 0.3, contour);
            Vector2[] line2 = { pm4, new Vector2(pm4.X, p0.Y) };
            fun.drawBLine(dxf, line2, 0.3, contour);
            Vector2[] line3 = { pm5, new Vector2(pm5.X, p0.Y) };
            fun.drawBLine(dxf, line3, 0.3, contour);
            Vector2[] line4 = { pm6, new Vector2(pm6.X, p0.Y + df / 2) };
            fun.drawBLine(dxf, line4, 0.3, contour);
            Vector2[] line5 = { pm7, new Vector2(pm7.X, p0.Y + df / 2) };
            fun.drawBLine(dxf, line5, 0.3, contour);
            Vector2[] line6 = { pm8, new Vector2(pm8.X, p0.Y + df / 2) };
            fun.drawBLine(dxf, line6, 0.3, contour);
            Vector2[] line7 = { p13, new Vector2(p13.X, p0.Y - df / 2) };
            fun.drawBLine(dxf, line7, 0.3, contour);
            Vector2[] line8 = { p14, new Vector2(p14.X, p0.Y - df / 2) };
            fun.drawBLine(dxf, line8, 0.3, contour);
            Vector2[] line9 = { p10, pm10 };
            fun.drawBLine(dxf, line9, 0.3, contour);

            Vector2[] cenline1 = { new Vector2(p0.X - 2, p0.Y), new Vector2(p0p.X + 2, p0.Y) };//主轴中心线
            fun.drawPlinetype(dxf, cenline1, centre, Linetype.Center);

            LwPolyline hatchpoly1 = new LwPolyline(); //填充
            hatchpoly1.Vertexes.Add(new LwPolylineVertex(p1));
            hatchpoly1.Vertexes.Add(new LwPolylineVertex(p2));
            hatchpoly1.Vertexes.Add(new LwPolylineVertex(p3));
            hatchpoly1.Vertexes.Add(new LwPolylineVertex(p4));
            hatchpoly1.Vertexes.Add(new LwPolylineVertex(p5));
            hatchpoly1.Vertexes.Add(new LwPolylineVertex(p6));
            hatchpoly1.Vertexes.Add(new LwPolylineVertex(p7));
            hatchpoly1.Vertexes.Add(new LwPolylineVertex(p8));
            hatchpoly1.Vertexes.Add(new LwPolylineVertex(p9));
            hatchpoly1.Vertexes.Add(new LwPolylineVertex(p15));
            hatchpoly1.Vertexes.Add(new LwPolylineVertex(p14));
            hatchpoly1.Vertexes.Add(new LwPolylineVertex(p13));
            hatchpoly1.IsClosed = true;
            String[] htype1 = new String[100];
            Line[] hline1 = new Line[100];
            int hnumst1 = hatchpoly1.Explode().Count;  //记录爆炸后，线段有多少
            for (int i = 0; i < hnumst1; i++)
            {
                htype1[i] = hatchpoly1.Explode()[i].Type.ToString();    //将所有的元素记录成一个数组
                if (htype1[i] == "Line")
                {
                    hline1[i] = (Line)hatchpoly1.Explode()[i];
                }
            }
            fun.hatchsubofline(dxf, htype1, hnumst1, 45, 5, hline1, hatching);

            DimensionStyle dimensionStyle = fun.CreateDimStyle();//标注
            dimensionStyle.ArrowSize = 0.2;
            dimensionStyle.DimArrow1 = DimensionArrowhead.Closedfilled;
            dimensionStyle.DimArrow2 = DimensionArrowhead.Closedfilled;
            dimensionStyle.TextHeight = 0.5;
            double offset = 7;

            LinearDimension linedim1 = new LinearDimension(new Line(p2, p9), offset * 5, 180, dimensionStyle);
            fun.dxflinedim(dxf, linedim1, oal);
            LinearDimension linedim2 = new LinearDimension(new Line(p8, pm8), offset * 3, 270, dimensionStyle);
            fun.dxflinedim(dxf, linedim2, bd);
            LinearDimension linedim3 = new LinearDimension(new Line(p2, p13), offset * 4, 180, dimensionStyle);
            fun.dxflinedim(dxf, linedim3, lcob);
            LinearDimension linedim4 = new LinearDimension(new Line(p14, p15), offset * 4, 180, dimensionStyle);
            fun.dxflinedim(dxf, linedim4, lsc);
            LinearDimension linedim5 = new LinearDimension(new Line(p3, pm3), offset, 90, dimensionStyle);
            fun.dxflinedim(dxf, linedim5, thod);
            LinearDimension linedim6 = new LinearDimension(new Line(p5, pm5), offset * 7, 90, dimensionStyle);
            fun.dxflinedim(dxf, linedim6, dgui);
            LinearDimension linedim7 = new LinearDimension(new Line(pm2, pm8), offset * 2, 0, dimensionStyle);
            fun.dxflinedim(dxf, linedim7, lcol);
            LinearDimension linedim8 = new LinearDimension(new Line(p9, pm9), offset * 1, 270, dimensionStyle);
            fun.dxflinedim(dxf, linedim8, dclc);

            dxf.DrawingVariables.AcadVer = DxfVersion.AutoCad2007;
            dxf.Save(path);
        }

        public static void DrawInColletsWithRetainingThread(Dictionary<string, Object> data)  //螺纹固定的拉缩夹头
        {
            DxfDocument dxf = new DxfDocument();
            Layer contour = new Layer("contour") { Color = AciColor.Cyan };    //轮廓层
            Layer dimensioning = new Layer("dimensioning");    //尺寸层
            Layer refin = new Layer("refin") { Color = AciColor.Red };    //基准线/内轮廓
            Layer centre = new Layer("centre") { Color = AciColor.Yellow };    //中心线
            Layer textlayer = new Layer("textlayer") { Color = AciColor.Blue };    //文本层
            Layer hatching = new Layer("hatching") { Color = AciColor.Blue };    //填充层
            Layer additionalline = new Layer("additionalline") { Color = AciColor.Cyan };    //附加线
            Layer cutting = new Layer("cutting") { Color = AciColor.Red };    //切削层
            Layer nocutting = new Layer("nocutting");    //非切削层
            Layer skcontour = new Layer("skcontour") { Color = AciColor.Cyan };    //sk轮廓层
            Layer skdimensioning = new Layer("skdimensioning");    //sk尺寸线层
            Layer skrefin = new Layer("skrefin") { Color = AciColor.Red };    //sk基准线/内轮廓
            Layer sktext = new Layer("sktext") { Color = AciColor.Blue };  //sk文本
            Layer skhatching = new Layer("skhatching") { Color = AciColor.Blue };    //sk填充
            Layer skadditionlline = new Layer("skadditionlline") { Color = AciColor.Cyan };    //sk附加线
            Layer skviewcontour = new Layer("skviewcontour") { Color = AciColor.Cyan };    //skview轮廓
            Layer skviewdimensioning = new Layer("skviewdimensioning");    //skview尺寸线层

            double pi = Math.PI;

            double oal = 120;
            double lsc = 32;
            double lcob = 80;
            double lcon = 28;
            double lcol = 115;
            double tl = 15;
            double lgui = 50;
            double thlgth = 30;
            double thod = 28;
            double dcob = 20;
            double dn = 26;
            double bd = 46;
            double dclc = 20;
            double dconws = 12;
            double x1 = 1;
            double x2 = 2;
            double h1 = 5;//开槽距中心线距离
            double ta = 60 * pi / 180;
            string path = "E:\\dxfp\\DrawInColletsWithRetainingThread.dxf";


            Vector2 p0 = new Vector2(0, 0);
            Vector2 p0p = new Vector2(p0.X + oal, p0.Y);
            Vector2 p1 = new Vector2(p0.X, p0.Y - thod / 2 + x2);
            Vector2 p2 = new Vector2(p0.X + x2, p0.Y - thod / 2);
            Vector2 p3 = new Vector2(p0.X + lgui, p2.Y);
            Vector2 p4 = new Vector2(p3.X + x1, p0.Y - dn / 2);
            Vector2 p5 = new Vector2(p0.X + lcol - tl, p4.Y);
            Vector2 p6 = new Vector2(p5.X + x1, p0.Y - (bd / 2 - (tl - x1) * Math.Tan(ta / 2)));
            Vector2 p7 = new Vector2(p0.X + lcol, p0.Y - bd / 2);
            Vector2 p8 = new Vector2(p0p.X, p0.Y - dclc / 2);
            Vector2 p9 = new Vector2(p0p.X, p0.Y - dconws / 2);
            Vector2 pm9 = new Vector2(p9.X, -p9.Y);
            Vector2 pm8 = new Vector2(p8.X, -p8.Y);
            Vector2 pm7 = new Vector2(p7.X, -p7.Y);
            Vector2 pm6 = new Vector2(p6.X, -p6.Y);
            Vector2 pm5 = new Vector2(p5.X, -p5.Y);
            Vector2 pm4 = new Vector2(p4.X, -p4.Y);
            Vector2 pm3 = new Vector2(p3.X, -p3.Y);
            Vector2 pm2 = new Vector2(p2.X, -p2.Y);
            Vector2 pm1 = new Vector2(p1.X, -p1.Y);
            Vector2 p10 = new Vector2((p1.X + p2.X) / 2, (p1.Y + p2.Y) / 2);
            Vector2 p11 = new Vector2(p0.X + lcon, p10.Y);
            Vector2 p12 = new Vector2(p11.X, p0.Y - thod / 2);
            Vector2 p13 = new Vector2(p0.X, p0.Y - dcob / 2);
            Vector2 p14 = new Vector2(p0.X + lcob, p13.Y);
            Vector2 p15 = new Vector2(p14.X + x2, p0.Y - (dcob + dconws) / 4);
            Vector2 p16 = new Vector2(p0.X + oal - lsc - x2, p15.Y);
            Vector2 p17 = new Vector2(p0p.X - lsc, p0.Y - dconws / 2);
            Vector2 p18 = new Vector2(p4.X, p13.Y);

            Vector2[] cenline1 = { new Vector2(p0.X - 2, p0.Y), new Vector2(p0p.X + 2, p0.Y) };//主轴中心线
            fun.drawPlinetype(dxf, cenline1, centre, Linetype.Center);

            LwPolyline poly1 = new LwPolyline(); //外轮廓
            poly1.Vertexes.Add(new LwPolylineVertex(p0));
            poly1.Vertexes.Add(new LwPolylineVertex(p1));
            poly1.Vertexes.Add(new LwPolylineVertex(p2));
            poly1.Vertexes.Add(new LwPolylineVertex(p3));
            poly1.Vertexes.Add(new LwPolylineVertex(p4));
            poly1.Vertexes.Add(new LwPolylineVertex(p5));
            poly1.Vertexes.Add(new LwPolylineVertex(p6));
            poly1.Vertexes.Add(new LwPolylineVertex(p7));
            poly1.Vertexes.Add(new LwPolylineVertex(p8));
            poly1.Vertexes.Add(new LwPolylineVertex(p9));
            poly1.Vertexes.Add(new LwPolylineVertex(pm9));
            poly1.Vertexes.Add(new LwPolylineVertex(pm8));
            poly1.Vertexes.Add(new LwPolylineVertex(pm7));
            poly1.Vertexes.Add(new LwPolylineVertex(pm6));
            poly1.Vertexes.Add(new LwPolylineVertex(pm5));
            poly1.Vertexes.Add(new LwPolylineVertex(pm4));
            poly1.Vertexes.Add(new LwPolylineVertex(pm3));
            poly1.Vertexes.Add(new LwPolylineVertex(pm2));
            poly1.Vertexes.Add(new LwPolylineVertex(pm1));
            poly1.IsClosed = true;
            fun.PolyFill(dxf, poly1, 0.3, contour);

            LwPolyline poly2 = new LwPolyline();
            poly2.Vertexes.Add(new LwPolylineVertex(p10));
            poly2.Vertexes.Add(new LwPolylineVertex(p11));
            poly2.Vertexes.Add(new LwPolylineVertex(p12));
            fun.PolyFill(dxf, poly2, 0.3, contour);

            LwPolyline poly3 = new LwPolyline();
            poly3.Vertexes.Add(new LwPolylineVertex(p13));
            poly3.Vertexes.Add(new LwPolylineVertex(p14));
            poly3.Vertexes.Add(new LwPolylineVertex(p15));
            poly3.Vertexes.Add(new LwPolylineVertex(p16));
            poly3.Vertexes.Add(new LwPolylineVertex(p17));
            poly3.Vertexes.Add(new LwPolylineVertex(p9));
            fun.PolyFill(dxf, poly3, 0.3, contour);

            Vector2[] line1 = { pm2, new Vector2(pm2.X, p0.Y) };
            fun.drawBLine(dxf, line1, 0.3, contour);
            Vector2[] line2 = { pm3, new Vector2(pm3.X, p0.Y) };
            fun.drawBLine(dxf, line2, 0.3, contour);
            Vector2[] line3 = { pm4, new Vector2(pm4.X, p0.Y) };
            fun.drawBLine(dxf, line3, 0.3, contour);

            double h2 = pm4.Y - h1 - x1;
            Vector2 pc1 = new Vector2(p4.X, p0.Y + h1);
            Vector2 pc2 = new Vector2(p5.X, pc1.Y);
            Vector2 pc3 = new Vector2(p6.X, pm6.Y - h2 - x2);
            Vector2 pc4 = new Vector2(p7.X, pm7.Y - 2 * h2);
            Vector2 pc5 = new Vector2(p8.X, pm8.Y - h2);
            Vector2 pc6 = new Vector2(pc5.X, pc5.Y + x1);
            Vector2 pc7 = new Vector2(pc4.X, pc4.Y + x1);
            Vector2 pc8 = new Vector2(pc3.X, pc3.Y + x1);
            Vector2 pc9 = new Vector2(pc2.X, pc2.Y + x1);
            Vector2 pc10 = new Vector2(pc1.X, pc1.Y + x1);

            LwPolyline poly4 = new LwPolyline();
            poly4.Vertexes.Add(new LwPolylineVertex(pc1));
            poly4.Vertexes.Add(new LwPolylineVertex(pc2));
            poly4.Vertexes.Add(new LwPolylineVertex(pc3));
            poly4.Vertexes.Add(new LwPolylineVertex(pc4));
            poly4.Vertexes.Add(new LwPolylineVertex(pc5));
            poly4.Vertexes.Add(new LwPolylineVertex(pc6));
            poly4.Vertexes.Add(new LwPolylineVertex(pc7));
            poly4.Vertexes.Add(new LwPolylineVertex(pc8));
            poly4.Vertexes.Add(new LwPolylineVertex(pc9));
            poly4.Vertexes.Add(new LwPolylineVertex(pc10));
            fun.PolyFill(dxf, poly4, 0.3, contour);

            Vector2[] line4 = { pm5, pc9 };
            fun.drawBLine(dxf, line4, 0.3, contour);
            Vector2[] line5 = { pm6, pc8 };
            fun.drawBLine(dxf, line5, 0.3, contour);
            Vector2[] line6 = { pm7, pc7 };
            fun.drawBLine(dxf, line6, 0.3, contour);
            Vector2[] line7 = { pc2, new Vector2(pc2.X, p0.Y) };
            fun.drawBLine(dxf, line7, 0.3, contour);
            Vector2[] line8 = { pc3, new Vector2(pc3.X, p0.Y) };
            fun.drawBLine(dxf, line8, 0.3, contour);
            Vector2[] line9 = { pc4, new Vector2(pc4.X, p0.Y) };
            fun.drawBLine(dxf, line9, 0.3, contour);
            Vector2[] line10 = { p4, p18 };
            fun.drawBLine(dxf, line10, 0.3, contour);
            Vector2[] line11 = { p14, new Vector2(p14.X, p0.Y) };
            fun.drawBLine(dxf, line11, 0.3, contour);
            Vector2[] line12 = { p15, new Vector2(p15.X, p0.Y) };
            fun.drawBLine(dxf, line12, 0.3, contour);
            Vector2[] line13 = { p16, new Vector2(p16.X, p0.Y) };
            fun.drawBLine(dxf, line13, 0.3, contour);
            Vector2[] line14 = { p17, new Vector2(p17.X, p0.Y) };
            fun.drawBLine(dxf, line14, 0.3, contour);

            LwPolyline hatchpoly1 = new LwPolyline(); //填充
            hatchpoly1.Vertexes.Add(new LwPolylineVertex(p1));
            hatchpoly1.Vertexes.Add(new LwPolylineVertex(p10));
            hatchpoly1.Vertexes.Add(new LwPolylineVertex(p11));
            hatchpoly1.Vertexes.Add(new LwPolylineVertex(p12));
            hatchpoly1.Vertexes.Add(new LwPolylineVertex(p3));
            hatchpoly1.Vertexes.Add(new LwPolylineVertex(p4));
            hatchpoly1.Vertexes.Add(new LwPolylineVertex(p18));
            hatchpoly1.Vertexes.Add(new LwPolylineVertex(p13));
            hatchpoly1.Vertexes.Add(new LwPolylineVertex(p1));
            hatchpoly1.IsClosed = true;
            String[] htype1 = new String[100];
            Line[] hline1 = new Line[100];
            int hnumst1 = hatchpoly1.Explode().Count;  //记录爆炸后，线段有多少
            for (int i = 0; i < hnumst1; i++)
            {
                htype1[i] = hatchpoly1.Explode()[i].Type.ToString();    //将所有的元素记录成一个数组
                if (htype1[i] == "Line")
                {
                    hline1[i] = (Line)hatchpoly1.Explode()[i];
                }
            }
            fun.hatchsubofline(dxf, htype1, hnumst1, 45, 5, hline1, hatching);

            LwPolyline hatchpoly2 = new LwPolyline(); //填充
            hatchpoly2.Vertexes.Add(new LwPolylineVertex(p10));
            hatchpoly2.Vertexes.Add(new LwPolylineVertex(p11));
            hatchpoly2.Vertexes.Add(new LwPolylineVertex(p12));
            hatchpoly2.Vertexes.Add(new LwPolylineVertex(p2));
            hatchpoly2.Vertexes.Add(new LwPolylineVertex(p10));
            hatchpoly2.IsClosed = true;
            String[] htype2 = new String[100];
            Line[] hline2 = new Line[100];
            int hnumst2 = hatchpoly2.Explode().Count;  //记录爆炸后，线段有多少
            for (int i = 0; i < hnumst2; i++)
            {
                htype2[i] = hatchpoly2.Explode()[i].Type.ToString();    //将所有的元素记录成一个数组
                if (htype2[i] == "Line")
                {
                    hline2[i] = (Line)hatchpoly2.Explode()[i];
                }
            }
            fun.hatchsubofline(dxf, htype2, hnumst2, 89.9, 5, hline2, hatching);

            DimensionStyle dimensionStyle = fun.CreateDimStyle();//标注
            dimensionStyle.ArrowSize = 0.2;
            dimensionStyle.DimArrow1 = DimensionArrowhead.Closedfilled;
            dimensionStyle.DimArrow2 = DimensionArrowhead.Closedfilled;
            dimensionStyle.TextHeight = 0.5;
            double offset = 7;

            LinearDimension linedim1 = new LinearDimension(new Line(p1, p8), offset * 4, 180, dimensionStyle);
            fun.dxflinedim(dxf, linedim1, oal);
            LinearDimension linedim2 = new LinearDimension(new Line(p7, pm7), offset * 3, 270, dimensionStyle);
            fun.dxflinedim(dxf, linedim2, bd);
            LinearDimension linedim3 = new LinearDimension(new Line(p13, p14), offset * 2, 180, dimensionStyle);
            fun.dxflinedim(dxf, linedim3, lcob);
            LinearDimension linedim4 = new LinearDimension(new Line(p17, p9), offset * 3, 180, dimensionStyle);
            fun.dxflinedim(dxf, linedim4, lsc);
            LinearDimension linedim5 = new LinearDimension(new Line(p2, pm2), offset, 90, dimensionStyle);
            fun.dxflinedim(dxf, linedim5, thod);
            LinearDimension linedim6 = new LinearDimension(new Line(p8, pm8), offset * 1, 270, dimensionStyle);
            fun.dxflinedim(dxf, linedim6, dclc);
            LinearDimension linedim7 = new LinearDimension(new Line(pm1, pm7), offset * 2, 0, dimensionStyle);
            fun.dxflinedim(dxf, linedim7, lcol);
            LinearDimension linedim8 = new LinearDimension(new Line(pm1, pm3), offset, 0, dimensionStyle);
            fun.dxflinedim(dxf, linedim8, lgui);


            Angular2LineDimension dimang1 = new Angular2LineDimension(new Line(pm6, pm7), new Line(p6, p7), 7 * offset, dimensionStyle);
            //标注相关点坐标距离应尽量缩短 
            dimang1.SetDimensionLinePosition(fun.Polar(p0p, 0, offset * 5));
            dimang1.UserText = String.Format("{0}%%d", ta * 180 / pi);
            dxf.AddEntity(dimang1);

            dxf.DrawingVariables.AcadVer = DxfVersion.AutoCad2007;
            dxf.Save(path);
        }
        
        public static void CylindricalClampingSleeves(Dictionary<string, Object> data) //未完成
        {
            DxfDocument dxf = new DxfDocument();
            Layer contour = new Layer("contour") { Color = AciColor.Cyan };    //轮廓层
            Layer dimensioning = new Layer("dimensioning");    //尺寸层
            Layer refin = new Layer("refin") { Color = AciColor.Red };    //基准线/内轮廓
            Layer centre = new Layer("centre") { Color = AciColor.Yellow };    //中心线
            Layer textlayer = new Layer("textlayer") { Color = AciColor.Blue };    //文本层
            Layer hatching = new Layer("hatching") { Color = AciColor.Blue };    //填充层
            Layer additionalline = new Layer("additionalline") { Color = AciColor.Cyan };    //附加线
            Layer cutting = new Layer("cutting") { Color = AciColor.Red };    //切削层
            Layer nocutting = new Layer("nocutting");    //非切削层
            Layer skcontour = new Layer("skcontour") { Color = AciColor.Cyan };    //sk轮廓层
            Layer skdimensioning = new Layer("skdimensioning");    //sk尺寸线层
            Layer skrefin = new Layer("skrefin") { Color = AciColor.Red };    //sk基准线/内轮廓
            Layer sktext = new Layer("sktext") { Color = AciColor.Blue };  //sk文本
            Layer skhatching = new Layer("skhatching") { Color = AciColor.Blue };    //sk填充
            Layer skadditionlline = new Layer("skadditionlline") { Color = AciColor.Cyan };    //sk附加线
            Layer skviewcontour = new Layer("skviewcontour") { Color = AciColor.Cyan };    //skview轮廓
            Layer skviewdimensioning = new Layer("skviewdimensioning");    //skview尺寸线层

            double pi = Math.PI;

            double oal = 100;
            double lsc = 76;
            double lcob = 22;
            double lcol = 95;
            double lgui = 10;
            double lcon = 77;
            double lc = 5;
            double x1 = 2;
            double x2 = 1;
            double dcon = 36;
            double dgui = 34;
            double dcob = 28;
            double dconws = 24;
            double bd = 46;
            double lk1 = 21;
            double lk2 = 25;
            double lf1 = oal - (lk1 + lk2) / 2;
            double lf2 = 75;
            double r1 = 2;
            double h1 = 8;


            Vector2 p0 = new Vector2(0, 0);
            Vector2 p0p = new Vector2(p0.X + oal, p0.Y);
            Vector2 p1 = new Vector2(p0.X, p0.Y - dcob / 2);
            Vector2 p2 = new Vector2(p0.X, p0.Y - dgui / 2 + x1);
            Vector2 p3 = new Vector2(p0.X + x1, p0.Y - dgui / 2);
            Vector2 p4 = new Vector2(p0.X + lgui, p3.Y);
            Vector2 p5 = new Vector2(p4.X + x1, p0.Y - dcon / 2);
            Vector2 p6 = new Vector2(p5.X + lcon, p5.Y);
            Vector2 p7 = new Vector2(p6.X + x1, p6.Y + 2);
            Vector2 p8 = new Vector2(p7.X + lc, p7.Y);
            Vector2 p9 = new Vector2(p8.X, p0.Y - bd / 2 + x2);
            Vector2 p10 = new Vector2(p9.X + x1, p0.Y - bd / 2);
            Vector2 p11 = new Vector2(p0p.X - x2, p10.Y);
            Vector2 p12 = new Vector2(p0p.X, p9.Y);
            Vector2 pm12 = new Vector2(p12.X, -p12.Y);
            Vector2 pm11 = new Vector2(p11.X, -p11.Y);
            Vector2 pm10 = new Vector2(p10.X, -p10.Y);
            Vector2 pm9 = new Vector2(p9.X, -p9.Y);
            Vector2 pm8 = new Vector2(p8.X, -p8.Y);
            Vector2 pm7 = new Vector2(p7.X, -p7.Y);
            Vector2 pm6 = new Vector2(p6.X, -p6.Y);
            Vector2 pm5 = new Vector2(p5.X, -p5.Y);
            Vector2 pm4 = new Vector2(p4.X, -p4.Y);
            Vector2 pm3 = new Vector2(p3.X, -p3.Y);
            Vector2 pm2 = new Vector2(p2.X, -p2.Y);
            Vector2 p13 = new Vector2(p0p.X, p0.Y - dconws / 2 - x1);//半剖面
            Vector2 p14 = new Vector2(p0p.X - x1, p0.Y - dconws / 2);
            Vector2 p15 = new Vector2(p0p.X - lsc, p14.X);
            Vector2 p16 = new Vector2(p0.X + lcob, p0.Y - dcob / 2);
            Vector2 p17 = new Vector2(p0.X + lk1, p15.Y);
            Vector2 p18 = new Vector2(p0.X + lk2, p15.Y);
            Vector2 p19 = new Vector2(p17.X, p5.Y);
            Vector2 p20 = new Vector2(p18.X, p19.Y);



            LwPolyline poly1 = new LwPolyline(); //外轮廓
            poly1.Vertexes.Add(new LwPolylineVertex(p0));
            poly1.Vertexes.Add(new LwPolylineVertex(p1));
            poly1.Vertexes.Add(new LwPolylineVertex(p2));
            poly1.Vertexes.Add(new LwPolylineVertex(p3));
            poly1.Vertexes.Add(new LwPolylineVertex(p4));
            poly1.Vertexes.Add(new LwPolylineVertex(p5));
            poly1.Vertexes.Add(new LwPolylineVertex(p6));
            poly1.Vertexes.Add(new LwPolylineVertex(p7));
            poly1.Vertexes.Add(new LwPolylineVertex(p8));
            poly1.Vertexes.Add(new LwPolylineVertex(p9));
            poly1.Vertexes.Add(new LwPolylineVertex(p10));
            poly1.Vertexes.Add(new LwPolylineVertex(p11));
            poly1.Vertexes.Add(new LwPolylineVertex(p12));
            poly1.Vertexes.Add(new LwPolylineVertex(pm12));
            poly1.Vertexes.Add(new LwPolylineVertex(pm11));
            poly1.Vertexes.Add(new LwPolylineVertex(pm10));
            poly1.Vertexes.Add(new LwPolylineVertex(pm9));
            poly1.Vertexes.Add(new LwPolylineVertex(pm8));
            poly1.Vertexes.Add(new LwPolylineVertex(pm7));
            poly1.Vertexes.Add(new LwPolylineVertex(pm6));
            poly1.Vertexes.Add(new LwPolylineVertex(pm5));
            poly1.Vertexes.Add(new LwPolylineVertex(pm4));
            poly1.Vertexes.Add(new LwPolylineVertex(pm3));
            poly1.Vertexes.Add(new LwPolylineVertex(pm2));
            poly1.IsClosed = true;
            fun.PolyFill(dxf, poly1, 0.3, contour);

            LwPolyline poly2 = new LwPolyline();
            poly2.Vertexes.Add(new LwPolylineVertex(p13));
            poly2.Vertexes.Add(new LwPolylineVertex(p14));
            poly2.Vertexes.Add(new LwPolylineVertex(p15));
            poly2.Vertexes.Add(new LwPolylineVertex(p16));
            poly2.Vertexes.Add(new LwPolylineVertex(p1));
            fun.PolyFill(dxf, poly2, 0.3, contour);

            Vector2[] cenline1 = { new Vector2(p0.X - 2, p0.Y), new Vector2(p0p.X + 2, p0.Y) };//主轴中心线
            fun.drawPlinetype(dxf, cenline1, centre, Linetype.Center);

            Vector2[] line1 = { p17, p19 };
            fun.drawBLine(dxf, line1, 0.3, contour);
            Vector2[] line2 = { p18, p20 };
            fun.drawBLine(dxf, line2, 0.3, contour);

            LwPolyline hatchpoly1 = new LwPolyline(); //填充
            hatchpoly1.Vertexes.Add(new LwPolylineVertex(p1));
            hatchpoly1.Vertexes.Add(new LwPolylineVertex(p2));
            hatchpoly1.Vertexes.Add(new LwPolylineVertex(p3));
            hatchpoly1.Vertexes.Add(new LwPolylineVertex(p4));
            hatchpoly1.Vertexes.Add(new LwPolylineVertex(p5));
            hatchpoly1.Vertexes.Add(new LwPolylineVertex(p19));
            hatchpoly1.Vertexes.Add(new LwPolylineVertex(p17));
            hatchpoly1.Vertexes.Add(new LwPolylineVertex(p15));
            hatchpoly1.Vertexes.Add(new LwPolylineVertex(p16));
            hatchpoly1.Vertexes.Add(new LwPolylineVertex(p1));
            hatchpoly1.IsClosed = true;
            String[] htype1 = new String[100];
            Line[] hline1 = new Line[100];
            int hnumst1 = hatchpoly1.Explode().Count;  //记录爆炸后，线段有多少
            for (int i = 0; i < hnumst1; i++)
            {
                htype1[i] = hatchpoly1.Explode()[i].Type.ToString();    //将所有的元素记录成一个数组
                if (htype1[i] == "Line")
                {
                    hline1[i] = (Line)hatchpoly1.Explode()[i];
                }
            }
            fun.hatchsubofline(dxf, htype1, hnumst1, 45, 5, hline1, hatching);

            Vector2 pf1 = new Vector2(p0.X, p0.Y + x2);
            Vector2 pf2 = new Vector2(p0.X + lf1 - r1, pf1.Y);
            Vector2 pf3 = new Vector2(pf2.X + 2 * r1, pf2.Y);
            Vector2 pf4 = new Vector2(pf3.X, -pf3.Y);
            Vector2 pf5 = new Vector2(pf2.X, -pf2.Y);
            Vector2 pf6 = new Vector2(pf1.X, -pf1.Y);

            Vector2 pl1 = new Vector2(p0p.X - lf2 - r1, p0.X + h1);
            Vector2 pl2 = new Vector2(pl1.X + 2 * r1, pl1.Y);
            Vector2 pl3 = new Vector2(p6.X, pl2.Y);
            Vector2 pl4 = new Vector2(p7.X, pl3.Y - x1);
            Vector2 pl5 = new Vector2(p8.X, pl4.Y);
            Vector2 pl6 = new Vector2(p10.X, pl5.Y + x1 + x2);
            Vector2 pl7 = new Vector2(p11.X, pl6.Y);
            Vector2 pl8 = new Vector2(p12.X, pl5.Y);
            Vector2 pl9 = new Vector2(pl8.X, pl8.Y + x1);
            Vector2 pl10 = new Vector2(pl7.X, pl7.Y + x1);
            Vector2 pl11 = new Vector2(pl6.X, pl6.Y + x1);
            Vector2 pl12 = new Vector2(pl5.X, pl5.Y + x1);
            Vector2 pl13 = new Vector2(pl4.X, pl4.Y + x1);
            Vector2 pl14 = new Vector2(pl3.X, pl3.Y + x1);
            Vector2 pl15 = new Vector2(pl2.X, pl2.Y + x1);
            Vector2 pl16 = new Vector2(pl1.X, pl1.Y + x1);

            LwPolyline poly3 = new LwPolyline();
            poly3.Vertexes.Add(new LwPolylineVertex(pf6));
            poly3.Vertexes.Add(new LwPolylineVertex(pf5));
            poly3.Vertexes[1].Bulge = Math.Tan(pi / 4);
            poly3.Vertexes.Add(new LwPolylineVertex(pf4));
            poly3.Vertexes.Add(new LwPolylineVertex(pf3));
            poly3.Vertexes[3].Bulge = Math.Tan(pi / 4);
            poly3.Vertexes.Add(new LwPolylineVertex(pf2));
            poly3.Vertexes.Add(new LwPolylineVertex(pf1));
            fun.PolyFill(dxf, poly3, 0.3, contour);

            LwPolyline poly4 = new LwPolyline();
            poly4.Vertexes.Add(new LwPolylineVertex(pf6));
            poly4.Vertexes.Add(new LwPolylineVertex(pf5));
            poly4.Vertexes[1].Bulge = Math.Tan(pi / 4);
            poly4.Vertexes.Add(new LwPolylineVertex(pf4));
            poly4.Vertexes.Add(new LwPolylineVertex(pf3));
            poly4.Vertexes[3].Bulge = Math.Tan(pi / 4);
            poly4.Vertexes.Add(new LwPolylineVertex(pf2));
            poly4.Vertexes.Add(new LwPolylineVertex(pf1));
            fun.PolyFill(dxf, poly4, 0.3, contour);
			

    }
        */

        public static void DoubleAngleCollet1(Dictionary<string, Object> data)  //双角夹头
        {
            DxfDocument dxf = new DxfDocument();
            Layer contour = new Layer("contour") { Color = AciColor.Cyan };    //轮廓层
            Layer dimensioning = new Layer("dimensioning");    //尺寸层
            Layer refin = new Layer("refin") { Color = AciColor.Red };    //基准线/内轮廓
            Layer centre = new Layer("centre") { Color = AciColor.Yellow };    //中心线
            Layer textlayer = new Layer("textlayer") { Color = AciColor.Blue };    //文本层
            Layer hatching = new Layer("hatching") { Color = AciColor.Blue };    //填充层
            Layer additionalline = new Layer("additionalline") { Color = AciColor.Cyan };    //附加线
            Layer cutting = new Layer("cutting") { Color = AciColor.Red };    //切削层
            Layer nocutting = new Layer("nocutting");    //非切削层
            Layer skcontour = new Layer("skcontour") { Color = AciColor.Cyan };    //sk轮廓层
            Layer skdimensioning = new Layer("skdimensioning");    //sk尺寸线层
            Layer skrefin = new Layer("skrefin") { Color = AciColor.Red };    //sk基准线/内轮廓
            Layer sktext = new Layer("sktext") { Color = AciColor.Blue };  //sk文本
            Layer skhatching = new Layer("skhatching") { Color = AciColor.Blue };    //sk填充
            Layer skadditionlline = new Layer("skadditionlline") { Color = AciColor.Cyan };    //sk附加线
            Layer skviewcontour = new Layer("skviewcontour") { Color = AciColor.Cyan };    //skview轮廓
            Layer skviewdimensioning = new Layer("skviewdimensioning");    //skview尺寸线层

            double pi = Math.PI;

            double bd = 48; //Convert.ToDouble(data["bd"]);
            double colst = 48; //Convert.ToDouble(data["colst"]);
            double dcob = 48; //Convert.ToDouble(data["dcob"]);
            double dconws = 48; //Convert.ToDouble(data["dconws"]);
            double dfc = 48; //Convert.ToDouble(data["dfc"]);
            double dgui = 48; //Convert.ToDouble(data["dgui"]);
            double gw = 48; //Convert.ToDouble(data["gw"]);
            double lcob = 48; //Convert.ToDouble(data["lcob"]);
            double lcol = 48; //Convert.ToDouble(data["lcol"]);
            double ldg = 48; //Convert.ToDouble(data["ldg"]);
            double lfsf = 48; //Convert.ToDouble(data["lfsf"]);
            double lsc = 48; //Convert.ToDouble(data["lsc"]);
            double oal = 48; //Convert.ToDouble(data["oal"]);
            double ta = 48; //Convert.ToDouble(data["ta"]);
            double ta2 = 48; //Convert.ToDouble(data["ta_2"]);
            string path = "E:\\dxfp\\DoubleAngleCollet.dxf"; // Convert.ToString(data["path"]);
            /*
            double bd = Convert.ToDouble(data["bd"]);
            double colst = Convert.ToDouble(data["colst"]);
            double dcob = Convert.ToDouble(data["dcob"]);
            double dconws = Convert.ToDouble(data["dconws"]);
            double dfc = Convert.ToDouble(data["dfc"]);
            double dgui = Convert.ToDouble(data["dgui"]);
            double gw = Convert.ToDouble(data["gw"]);
            double lcob = Convert.ToDouble(data["lcob"]);
            double lcol = Convert.ToDouble(data["lcol"]);
            double ldg = Convert.ToDouble(data["ldg"]);
            double lfsf = Convert.ToDouble(data["lfsf"]);
            double lsc = Convert.ToDouble(data["lsc"]);
            double oal = Convert.ToDouble(data["oal"]);
            double ta = Convert.ToDouble(data["ta"]);
            double ta2 = Convert.ToDouble(data["ta_2"]);
            string path = Convert.ToString(data["path"]);
            */

            double kjx = bd / 10; //间隙宽度

            Vector2 p0 = new Vector2(0, 0);
            Vector2 p0y = fun.Polar(p0, 0, ldg + lfsf);
            Vector2 p0z = fun.Polar(p0, pi, oal);
            Vector2 p2 = new Vector2(p0.X + ldg, p0.Y + bd / 2);
            Vector2 p1 = new Vector2(p2.X + lfsf, p2.Y - lfsf * Math.Tan(ta2 / 2));
            Vector2 p3 = new Vector2(p2.X, p0.Y + dcob / 2);
            Vector2 p4 = fun.Polar(p3, pi, gw);
            Vector2 p5 = new Vector2(p4.X, p0.Y + dfc / 2 + (ldg - gw) * Math.Tan(ta / 2));
            Vector2 p6 = new Vector2(p0z.X, p5.Y - (oal - lfsf - gw) * Math.Tan(ta / 2));
            Vector2 p6p = new Vector2(p6.X, p0.Y - p6.Y);
            Vector2 p5p = new Vector2(p5.X, p0.Y - p5.Y);
            Vector2 p4p = new Vector2(p4.X, p0.Y - p4.Y);
            Vector2 p3p = new Vector2(p3.X, p0.Y - p3.Y);
            Vector2 p2p = new Vector2(p2.X, p0.Y - p2.Y);
            Vector2 p1p = new Vector2(p1.X, p0.Y - p1.Y);
            Vector2 P9 = new Vector2(p0y.X, p0.Y + kjx / 2);
            Vector2 p9p = new Vector2(p0z.X, P9.Y);
            Vector2 p10 = new Vector2(p1.X, p0.Y + (p1.Y - p0.Y) / 2 - 0.5 * kjx * Math.Sin(pi / 3));
            Vector2 p11 = new Vector2(p2.X, p0.Y + (p2.Y - p0.Y) / 2 - 0.5 * kjx * Math.Sin(pi / 3));
            Vector2 p12 = new Vector2(p3.X, p0.Y + (p3.Y - p0.Y) / 2 - 0.5 * kjx * Math.Sin(pi / 3));
            Vector2 p13 = new Vector2(p4.X, p12.Y);
            Vector2 p14 = new Vector2(p5.X, p0.Y + (p5.Y - p0.Y) / 2 - 0.5 * kjx * Math.Sin(pi / 3));
            Vector2 fzp1 = fun.Inters(p5, p6, new Vector2(p0.X - 0.9 * oal, p0.Y), new Vector2(p0.X - 0.9 * oal, p0.Y + 100));
            Vector2 p15 = new Vector2(fzp1.X, p0.Y + (fzp1.Y - p0.Y) / 2 - 0.5 * kjx * Math.Sin(pi / 3));
            Vector2 p16 = new Vector2(fzp1.X, p0.Y + (fzp1.Y - p0.Y) / 2 + 0.5 * kjx * Math.Sin(pi / 3));
            Vector2 p17 = new Vector2(p5.X, p0.Y + (p5.Y - p0.Y) / 2 + 0.5 * kjx * Math.Sin(pi / 3));
            Vector2 p18 = new Vector2(p4.X, p0.Y + (p4.Y - p0.Y) / 2 + 0.5 * kjx * Math.Sin(pi / 3));
            Vector2 p19 = new Vector2(p3.X, p18.Y);
            Vector2 p20 = new Vector2(p2.X, p0.Y + (p2.Y - p0.Y) / 2 + 0.5 * kjx * Math.Sin(pi / 3));
            Vector2 p21 = new Vector2(p1.X, p0.Y + (p1.Y - p0.Y) / 2 + 0.5 * kjx * Math.Sin(pi / 3));
            Vector2 p22 = new Vector2(p2.X, P9.Y);
            Vector2 p23 = new Vector2(p5.X, P9.Y);



        }
        public static void DoubleAngleCollet(Dictionary<string, Object> data)   //转换器,旋转对称
        {
            DxfDocument dxf = new DxfDocument();
            //图层
            Layer contour = new Layer("contour") { Color = AciColor.Cyan };    //轮廓层
            Layer dimensioning = new Layer("dimensioning");    //尺寸层
            Layer refin = new Layer("refin") { Color = AciColor.Red };    //基准线/内轮廓
            Layer centre = new Layer("centre") { Color = AciColor.Yellow };    //中心线
            Layer textlayer = new Layer("textlayer") { Color = AciColor.Blue };    //文本层
            Layer hatching = new Layer("hatching") { Color = AciColor.Blue };    //填充层
            Layer additionalline = new Layer("additionalline") { Color = AciColor.Cyan };    //附加线
            Layer cutting = new Layer("cutting") { Color = AciColor.Red };    //切削层
            Layer nocutting = new Layer("nocutting");    //非切削层
            Layer skcontour = new Layer("skcontour") { Color = AciColor.Cyan };    //sk轮廓层
            Layer skdimensioning = new Layer("skdimensioning");    //sk尺寸线层
            Layer skrefin = new Layer("skrefin") { Color = AciColor.Red };    //sk基准线/内轮廓
            Layer sktext = new Layer("sktext") { Color = AciColor.Blue };  //sk文本
            Layer skhatching = new Layer("skhatching") { Color = AciColor.Blue };    //sk填充
            Layer skadditionlline = new Layer("skadditionlline") { Color = AciColor.Cyan };    //sk附加线
            Layer skviewcontour = new Layer("skviewcontour") { Color = AciColor.Cyan };    //skview轮廓
            Layer skviewdimensioning = new Layer("skviewdimensioning");    //skview尺寸线层
            //作图
            //参数
            double oal = Convert.ToDouble(data["oal"]);
            double dcob = Convert.ToDouble(data["dcob"]);
            double dfc = Convert.ToDouble(data["dfc"]);
            double pi = Math.PI;
            double ta = Convert.ToDouble(data["ta"]) * pi / 180;
            double dgui = Convert.ToDouble(data["dgui"]);
            double gw = Convert.ToDouble(data["gw"]);
            double lfsf = Convert.ToDouble(data["lfsf"]);
            double ta2 = Convert.ToDouble(data["ta2"]) * pi / 180;
            double lcob = Convert.ToDouble(data["lcob"]);
            double lclc = Convert.ToDouble(data["lclc"]);
            double dclc = Convert.ToDouble(data["dclc"]);
            double dconws = Convert.ToDouble(data["dconws"]);
            double lsc = Convert.ToDouble(data["lsc"]);
            string path = Convert.ToString(data["path"]);
            Vector2 v1 = new Vector2(0, 0);
            Vector2 v2 = new Vector2(v1.X, v1.Y + dfc - dcob * 2);
            Vector2 v3 = new Vector2(v1.X + dcob / Math.Tan(ta / 2), v2.Y + dcob + (dfc - dgui));
            Vector2 v4 = new Vector2(v3.X, v3.Y - (dfc - dgui));
            Vector2 v5 = new Vector2(v4.X + gw, v4.Y);
            Vector2 v6 = new Vector2(v5.X, Math.Tan(ta2 / 2) * lfsf / (1 + Math.Tan(ta2 / 2)) + v3.Y);
            Vector2 v7 = new Vector2(Math.Tan(ta2 / 2) * lfsf / (1 + Math.Tan(ta2 / 2)) + v6.X, v6.Y + Math.Tan(ta / 2) * Math.Tan(ta2 / 2) * lfsf / (1 + Math.Tan(ta2 / 2)));
            Vector2 v8 = new Vector2(v7.X + lfsf - Math.Tan(ta2 / 2) * lfsf / (1 + Math.Tan(ta2 / 2)), v4.Y);
            Vector2 v9 = new Vector2(v4.X, v4.Y - dgui / 2 + (dfc - dgui));
            Vector2 v10 = new Vector2(v5.X, v5.Y - dgui / 2 + (dfc - dgui));
            Vector2 v11 = new Vector2(v8.X, v8.Y - dgui / 2 + (dfc - dgui));
            Vector2 v12 = new Vector2(v4.X, v1.Y - dcob - (dfc - dgui));
            Vector2 v13 = new Vector2(v1.X, v1.Y + dcob);
            Vector2 v14 = new Vector2(v13.X + lcob, v13.Y);
            Vector2 v15 = new Vector2(v12.X, v12.Y + (dfc - dgui));
            Vector2 v16 = new Vector2(v15.X + gw, v15.Y);
            Vector2 v17 = new Vector2(v16.X, v12.Y - Math.Tan(ta2 / 2) * lfsf / (1 + Math.Tan(ta2 / 2)));
            Vector2 v18 = new Vector2(Math.Tan(ta2 / 2) * lfsf / (1 + Math.Tan(ta2 / 2)) + v17.X, v17.Y - Math.Tan(ta / 2) * Math.Tan(ta2 / 2) * lfsf / (1 + Math.Tan(ta2 / 2)));
            Vector2 v19 = new Vector2(v18.X + lfsf - Math.Tan(ta2 / 2) * lfsf / (1 + Math.Tan(ta2 / 2)), v15.Y);
            Vector2 v20 = new Vector2(v8.X, v8.Y - (dgui / 2 + (dfc - dgui)) / 2);
            Vector2 v21 = new Vector2(v20.X + lclc, v20.Y);
            Vector2 v22 = new Vector2(v21.X, v21.Y - dclc);
            Vector2 v23 = new Vector2(v21.X - lclc, v22.Y);
            Vector2 v24 = new Vector2(v14.X + (oal - lsc - lcob), v22.Y + (dclc - dconws));
            Vector2 v25 = new Vector2(v21.X, v24.Y);
            Vector2 v26 = new Vector2(v1.X + lcob, v1.Y - dcob / 4);
            // 线段
            //主视图
            Vector2[] Line1 = { v1, v2 };
            fun.drawBLine(dxf, Line1, 0.3, contour);
            Vector2[] Line2 = { v2, v3 };
            fun.drawBLine(dxf, Line2, 0.3, contour);
            Vector2[] Line3 = { v3, v4 };
            fun.drawBLine(dxf, Line3, 0.3, contour);
            Vector2[] Line4 = { v4, v5 };
            fun.drawBLine(dxf, Line4, 0.3, contour);
            Vector2[] Line6 = { v5, v6 };
            fun.drawBLine(dxf, Line6, 0.3, contour);
            Vector2[] Line7 = { v6, v7 };
            fun.drawBLine(dxf, Line7, 0.3, contour);
            Vector2[] Line8 = { v7, v8 };
            fun.drawBLine(dxf, Line8, 0.3, contour);
            Vector2[] Line9 = { v4, v9 };
            fun.drawBLine(dxf, Line9, 0.3, contour);
            Vector2[] Line10 = { v5, v10 };
            fun.drawBLine(dxf, Line10, 0.3, contour);
            Vector2[] Line11 = { v8, v11 };
            fun.drawBLine(dxf, Line11, 0.3, contour);
            Vector2[] Line12 = { v1, v12 };
            fun.drawBLine(dxf, Line12, 0.3, contour);
            Vector2[] Line13 = { v13, v14 };
            fun.drawBLine(dxf, Line13, 0.3, contour);
            Vector2[] Line14 = { v12, v15 };
            fun.drawBLine(dxf, Line14, 0.3, contour);
            Vector2[] Line15 = { v15, v16 };
            fun.drawBLine(dxf, Line15, 0.3, contour);
            Vector2[] Line16 = { v16, v17 };
            fun.drawBLine(dxf, Line16, 0.3, contour);
            Vector2[] Line17 = { v17, v18 };
            fun.drawBLine(dxf, Line17, 0.3, contour);
            Vector2[] Line18 = { v18, v19 };
            fun.drawBLine(dxf, Line18, 0.3, contour);
            Vector2[] Line19 = { v20, v21 };
            fun.drawBLine(dxf, Line19, 0.3, contour);
            Vector2[] Line20 = { v21, v22 };
            fun.drawBLine(dxf, Line20, 0.3, contour);
            Vector2[] Line21 = { v22, v23 };
            fun.drawBLine(dxf, Line21, 0.3, contour);
            Vector2[] Line22 = { v19, v23 };
            fun.drawBLine(dxf, Line22, 0.3, contour);
            Vector2[] Line23 = { v14, v24 };
            fun.drawBLine(dxf, Line23, 0.3, contour);
            Vector2[] Line24 = { v24, v25 };
            fun.drawBLine(dxf, Line24, 0.3, contour);
            //标注样式
            //箭头样式
            DimensionStyle dimensionStyle = fun.CreateDimStyle();
            dimensionStyle.ArrowSize = 0.2;
            dimensionStyle.DimArrow1 = DimensionArrowhead.Closedfilled;
            dimensionStyle.DimArrow2 = DimensionArrowhead.Closedfilled;
            //文本样式
            dimensionStyle.TextHeight = 1.0 / 2;
            double offset = 10;
            //线段尺寸标注
            //尺寸1
            LinearDimension dim1 = new LinearDimension(new Line(v4, v15), -v4.Y + v1.X - offset, 270, dimensionStyle);
            dim1.UserText = "DGUI ";
            dxf.AddEntity(dim1);
            //尺寸2
            LinearDimension dim2 = new LinearDimension(new Line(v6, v17), -v6.Y + v1.X - offset * 2, 270, dimensionStyle);
            dim2.UserText = "DFC  ";
            dxf.AddEntity(dim2);
            //尺寸3
            LinearDimension dim3 = new LinearDimension(new Line(v1, v25), -v25.Y + v1.X - offset * 2, 360, dimensionStyle);
            dim3.UserText = "OAL ";
            dxf.AddEntity(dim3);
            //尺寸4
            LinearDimension dim4 = new LinearDimension(new Line(v1, v8), -v8.Y + v1.X - offset / 5, 180, dimensionStyle);
            dim4.UserText = "LCOL ";
            dxf.AddEntity(dim4);
            //尺寸5
            LinearDimension dim5 = new LinearDimension(new Line(v4, v6), -v6.X + v4.X - offset / 6, 180, dimensionStyle);
            dim5.UserText = "GW ";
            dxf.AddEntity(dim5);
            //尺寸6
            LinearDimension dim6 = new LinearDimension(new Line(v17, v19), -v19.X + v17.X - offset / 5, 360, dimensionStyle);
            dim6.UserText = "LFSF ";
            dxf.AddEntity(dim6);
            //尺寸7
            LinearDimension dim7 = new LinearDimension(new Line(v19, v21), -v21.X + v19.X - offset / 4, 360, dimensionStyle);
            dim7.UserText = "LCLC ";
            dxf.AddEntity(dim7);
            //尺寸8
            LinearDimension dim8 = new LinearDimension(new Line(v20, v25), -v25.X + v20.X - offset / 3, 90, dimensionStyle);
            dim8.UserText = "DCONWS ";
            dxf.AddEntity(dim8);
            //尺寸9
            LinearDimension dim9 = new LinearDimension(new Line(v20, v22), -v22.X + v20.X - offset, 90, dimensionStyle);
            dim9.UserText = "DCLC ";
            dxf.AddEntity(dim9);
            //尺寸10
            LinearDimension dim10 = new LinearDimension(new Line(v4, v17), -v17.X + v4.X - offset * 2, 90, dimensionStyle);
            dim10.UserText = "BD ";
            dxf.AddEntity(dim10);
            //尺寸11
            LinearDimension dim11 = new LinearDimension(new Line(v22, v24), -v24.X + v22.X - offset * 3, 360, dimensionStyle);
            dim11.UserText = "LSC ";
            dxf.AddEntity(dim11);
            //尺寸12
            LinearDimension dim12 = new LinearDimension(new Line(v1, v14), -v14.X + v1.X - offset, 360, dimensionStyle);
            dim12.UserText = "LCOB ";
            dxf.AddEntity(dim12);
            //尺寸13
            Angular2LineDimension dimang1 = new Angular2LineDimension(new Line(v18, v19), new Line(v7, v8), offset + dcob / Math.Tan(ta2 / 2), dimensionStyle);
            dimang1.UserText = "TA2 = " + Math.Round(ta2 / (pi / 180), 2) + "°";
            dxf.AddEntity(dimang1);
            //尺寸14
            Angular2LineDimension dimang2 = new Angular2LineDimension(new Line(v18, v17), new Line(v7, v6), offset + oal / Math.Tan(ta2 / 2), dimensionStyle);
            dimang2.UserText = "TA = " + Math.Round(ta / (pi / 180), 2) + "°";
            dxf.AddEntity(dimang2);
            //填充
            LwPolyline hatchpoly1 = new LwPolyline();
            hatchpoly1.Vertexes.Add(new LwPolylineVertex(v1));
            hatchpoly1.Vertexes.Add(new LwPolylineVertex(v13));
            hatchpoly1.Vertexes.Add(new LwPolylineVertex(v14));
            hatchpoly1.Vertexes.Add(new LwPolylineVertex(v26));
            hatchpoly1.IsClosed = true;
            String[] htype1 = new String[100];
            Line[] hline1 = new Line[100];
            int hnumst1 = hatchpoly1.Explode().Count;  //记录爆炸后，线段有多少
            for (int i = 0; i < hnumst1; i++)
            {
                htype1[i] = hatchpoly1.Explode()[i].Type.ToString();    //将所有的元素记录成一个数组
                if (htype1[i] == "Line")
                {
                    hline1[i] = (Line)hatchpoly1.Explode()[i];
                }
            }
            fun.hatchsubofline(dxf, htype1, hnumst1, 89, 3, hline1, hatching);


            double isframe = Convert.ToInt32(data["isframe"]);
            String isframe_chose = Convert.ToString(data["isframe_chose"]);
            double scale = Convert.ToDouble(data["scale"]); //放大系数
            Vector2 p0 = new Vector2(0, 0);
            if (isframe == 1)
            {
                if (isframe_chose.Equals("0"))
                {
                    Dictionary<string, Vector2> position = Frame.frameA0X(dxf, new Vector2(p0.X - 1189 / 2.0, p0.Y + 841 / 2.0), data);
                    fun.writetext(dxf, scale + ":1", position["比例"], 3.5, 0, 0.6, "C");
                }

                if (isframe_chose.Equals("1"))
                {
                    Dictionary<string, Vector2> position = Frame.frameA1X(dxf, new Vector2(p0.X - 841 / 2.0, p0.Y + 594 / 2.0), data);
                    fun.writetext(dxf, scale + ":1", position["比例"], 3.5, 0, 0.6, "C");
                }

                if (isframe_chose.Equals("2"))
                {
                    Dictionary<string, Vector2> position = Frame.frameA2X(dxf, new Vector2(p0.X - 594 / 2.0, p0.Y + 420 / 2.0), data);
                    fun.writetext(dxf, scale + ":1", position["比例"], 3.5, 0, 0.6, "C");
                }

                if (isframe_chose.Equals("3"))
                {
                    Dictionary<string, Vector2> position = Frame.frameA3X(dxf, new Vector2(p0.X - 420 / 2.0, p0.Y + 297 / 2.0), data);
                    fun.writetext(dxf, scale + ":1", position["比例"], 3.5, 0, 0.6, "C");
                }

                if (isframe_chose.Equals("4X"))
                {
                    Dictionary<string, Vector2> position = Frame.frameA4X(dxf, new Vector2(p0.X - 297 / 2.0, p0.Y + 210 / 2.0 - 10 * 2.26), data);
                    fun.writetext(dxf, scale + ":1", position["比例"], 3.5, 0, 0.6, "C");
                }

                if (isframe_chose.Equals("4Y"))
                {
                    Dictionary<string, Vector2> position = Frame.frameA4Y(dxf, new Vector2(p0.X - 210 / 2.0, p0.Y + 297 / 2.0), data);
                    fun.writetext(dxf, scale + ":1", position["比例"], 3.5, 0, 0.6, "C");
                }
            }


            //定义格式，根据路径导出
            dxf.DrawingVariables.AcadVer = DxfVersion.AutoCad2007;
            dxf.Save(path);
        }
    }
}
